package oj;

import stack_quene.stack.stack.Stack;

public class Num20 {
    public boolean isValid(String s) {
        Stack stack=new Stack();
        char[] ret=s.toCharArray();
        for (int i = 0; i < ret.length; i++) {
            char c=ret[i];
            if(c=='('|| c=='['|| c=='{'){
                stack.push(c);
            }else{
                //]
                if(stack.isEmpty()){
                    return false;
                }
                char tmp= (char) stack.pop();
                if(c==']' && tmp!='['){
                    return false;
                }
                if(c=='}' && tmp!='{'){
                    return false;
                }
                if(c==')' && tmp!='('){
                    return false;
                }
            }
        }
        return stack.isEmpty();


    }
}
